﻿using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;
using UnityEngine.Events;

public class EzMonoManager : Singleton<EzMonoManager>
{

    EzMonoComponent ezMonoComponent;
    public EzMonoManager()
    {
        GameObject EzMonoManager = new GameObject("EzMonoManager");
        ezMonoComponent = EzMonoManager.AddComponent<EzMonoComponent>();
    }

    public void AddUpDateListener(UnityAction fuc)
    {
        CreateMonoManager();
        ezMonoComponent.AddUpDateListener(fuc);
    }
	
    public void RemoveUpdateListener(UnityAction fuc)
    {
        CreateMonoManager();
        ezMonoComponent.RemoveUpdateListener(fuc);
    }

    public Coroutine StartCoroutine(IEnumerator routine)
    {
        CreateMonoManager();
        return ezMonoComponent.StartCoroutine(routine);
    }

    public Coroutine StartCoroutine(string methodName, [DefaultValue("null")] object value)
    {
        CreateMonoManager();
        return ezMonoComponent.StartCoroutine(methodName, value);
    }

    public Coroutine StartCoroutine(string methodName)
    {
        CreateMonoManager();
        return ezMonoComponent.StartCoroutine(methodName);
    }


    public Coroutine StartCoroutine_Auto(IEnumerator routine)
    {
        CreateMonoManager();
        return ezMonoComponent.StartCoroutine(routine);
    }


    public void StopAllCoroutines()
    {
        CreateMonoManager();
        ezMonoComponent.StopAllCoroutines();
    }
    public void StopCoroutine(string methodName)
    {
        CreateMonoManager();
        ezMonoComponent.StopCoroutine(methodName);
    }
    
    public void StopCoroutine(IEnumerator routine)
    {
        CreateMonoManager();
        ezMonoComponent.StopCoroutine(routine);
    }

    public void StopCoroutine(Coroutine routine)
    {
        CreateMonoManager();
        ezMonoComponent.StopCoroutine(routine);

    }

    private void CreateMonoManager()
    {
        if (ezMonoComponent == null)
        {
            GameObject EzMonoManager = GameObject.Find("EzMonoManager");
            if (EzMonoManager != null)
            {
                if (EzMonoManager.GetComponent<EzMonoComponent>()==null)
                {
                    ezMonoComponent = EzMonoManager.AddComponent<EzMonoComponent>();
                }
            }
            else
            {
                EzMonoManager = new GameObject("EzMonoManager");
                ezMonoComponent = EzMonoManager.AddComponent<EzMonoComponent>();
            }
        }
    }

}
